#
# Copyright (c) 2022. China Mobile (SuZhou) Software Technology Co.,Ltd. All rights reserved.
# Lakehouse is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#          http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
#

# Usage:
# $ cd ${LAKEHOUSE_HOME}/docker/hive
# $ docker build -f Dockerfile -t ${your_docker_hub}/${your_docker_repo}/hive:3.1.2 .
# $ docker push ${your_docker_hub}/${your_docker_repo}/hive:3.1.2

FROM openjdk:8-jre-slim

RUN set -ex && \
    sed -i 's/http:\/\/deb.\(.*\)/https:\/\/deb.\1/g' /etc/apt/sources.list && \
    apt-get update && \
    ln -s /lib /lib64 && \
    apt install -y bash tini libc6 libpam-modules krb5-user libnss3 procps curl && \
    curl -O -L https://mirrors.bfsu.edu.cn/apache/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz && \
    tar zxf apache-hive-3.1.2-bin.tar.gz && \
    mv apache-hive-3.1.2-bin /opt/hive && \
    curl -O -L https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/5.1.35/mysql-connector-java-5.1.35.jar && \
    mv mysql-connector-java-5.1.35.jar /opt/hive/lib && \
    curl -O -L https://archive.apache.org/dist/hadoop/core/hadoop-3.1.0/hadoop-3.1.0.tar.gz && \
    tar zxf hadoop-3.1.0.tar.gz && \
    mv hadoop-3.1.0 /opt/hadoop && \
    cp /opt/hadoop/share/hadoop/tools/lib/aws-java-sdk-bundle-1.11.271.jar /opt/hive/lib && \
    cp /opt/hadoop/share/hadoop/tools/lib/hadoop-aws-3.1.0.jar /opt/hive/lib && \
    rm -f apache-hive-3.1.2-bin.tar.gz hadoop-3.1.0.tar.gz

ENV HADOOP_HOME=/opt/hadoop \
    HADOOP_MAPRED_HOME=/opt/hadoop \
    HADOOP_COMMON_HOME=/opt/hadoop \
    HADOOP_HDFS_HOME=/opt/hadoop \
    HADOOP_CONF_DIR=/opt/hadoop/etc/hadoop \
    HIVE_HOME=/opt/hive \
    PATH=/opt/hive/bin:/opt/hadoop/bin:/opt/hadoop/sbin:$PATH

RUN groupadd hadoop \
  && useradd -g hadoop hive \
  && chown -Rh hive:hadoop /opt/hadoop \
  && chown -Rh hive:hadoop /opt/hive

USER hive
WORKDIR /opt/hive